<?php
	
	include_once "../../php/inc/defines.php";
	include_once "../../php/auth.php";
	include_once "../layout.php";
	include_once "../../php/treenode.php";
	include_once "../../php/formhandler.php";
	include_once "../../php/sqlhandler.php";
	
	session_start();
	auth::secure(ADMIN);
	
	$tabs = array("Gestion des examens", "exam.php", "Gestion des &eacute;tudiants", "etu.php", "Directeurs des &eacute;tudes", "dde.php", "Administrateurs", "admin.php", "Recherche", "search.php");
	layout::displayPageHeader($tabs, $tabs[2], TRUE, "treediv2");
	
?>
<div class="arborescence" id="treeViewDiv">
	<?php
		$tree1 = unserialize($_SESSION["etuTree1"]);
		treenode::treeToHtml($tree1, ADMIN_1, 4);
	?>
</div>
<div class="content">
		<?php
		
		$nodeTypes[ADMIN_1][0] = "semestres";
		$nodeTypes[ADMIN_1][1] = "groupes TD";
		$nodeTypes[ADMIN_1][2] = "groupes TP";
		$nodeTypes[ADMIN_1][3] = "&eacute;tudiants";
		if(isset($_GET["nodetype"])) {
			echo "<h1>Gestion des ".$nodeTypes[$_GET["treetype"]][$_GET["nodetype"]]." de \"".$_GET["nodename"]."\"</h1>";
			$fh = new formhandler();
			switch($nodeTypes[$_GET["treetype"]][$_GET["nodetype"]]) {
				case "semestres":
					$fh->getForm("SELECT id_sem, nom_sem FROM ".SEMESTRE_TABLE." WHERE id_form=".$_GET["id"], SEMESTRE_TABLE, array("id_sem", "NULL", false, "", "id_form", $_GET["id"], false, "", "nom_sem", "", true, "Nom"));
					break;
				case "groupes TD":
					$fh->getForm("SELECT id_grptd, nom_grptd FROM ".GRP_TD_TABLE." WHERE id_sem=".$_GET["id"], GRP_TD_TABLE, array("id_grptd", "NULL", false, "", "id_sem", $_GET["id"], false, "", "nom_grptd", "", true, "Nom"));
					break;
				case "groupes TP":
					$fh->getForm("SELECT id_grptp, nom_grptp FROM ".GRP_TP_TABLE." WHERE id_grptd=".$_GET["id"], GRP_TP_TABLE, array("id_grptp", "NULL", false, "", "id_grptd", $_GET["id"], false, "", "nom_grptp", "", true, "Nom"));
					break;
				case "&eacute;tudiants":
					if($_GET["treetype"] == 0)
						$fh->getForm("SELECT id_etud, login, password FROM ".ETUDIANT_TABLE." WHERE id_grptp=\"".$_GET["id"]."\"", ETUDIANT_TABLE, array("id_etud", "NULL", false, "", "id_grptp", $_GET["id"], false, "", "id_parcours", "NULL", false, "", "login", "", true, "Identifiant", "password", "", true, "Mot de passe", "nom", "", false, "", "prenom", "", false, "", "apogee", "", false, ""));
					$sh = new sqlhandler();
					$groupesTP = $sh->getGroupesTPMemeSemestre($_GET["id"]);
					echo "<hr>";
					echo "<div class=\"bottomPageBar\">";
					echo "<button class=\"left\" onclick=\"window.open('../csv.php?tpid=".$_GET["id"]."&amp;tpnom=".$_GET["nodename"]."', 'popUpWindow','height=453,width=418,left=0,top=0,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');\">Ajout par fichier CSV</button>";
					echo "<form action=\"../../php/doaction.php\" method=\"post\">";
					echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET["id"]."\">";
					echo "<button class=\"left\" name=\"button\" type=\"submit\" value=\"suppr_tous\" onclick=\"return confirm('Voulez-vous vraiment supprimer tous les &eacute;tudiants de ce groupe TP ?')\">Supprimer tous les &eacute;tudiants du groupe</button>";
					echo "</form>";
					echo "<form action=\"../../php/doaction.php\" method=\"post\">";
					echo "<div class=\"right\">";
					echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET["id"]."\">";
					echo "<label>D&eacute;placer tous les &eacute;tudiants vers le groupe :&nbsp;</label>";
					echo "<select name=\"id_grptp\">";
					foreach($groupesTP as $tp=>$groupe)
						echo "<option value=\"".$tp."\">".$groupe."</option>";
					echo "</select>";
					echo "<button name=\"button\" type=\"submit\" value=\"depl_tous\">Valider</button>";
					echo "</div>";
					echo "</form>";
					echo "</div>";
					break;
			}

		}
		else {
			echo "<h1>Gestion des formations</h1>";
			$fh = new formhandler();
			$fh->getForm("SELECT id_form, nom_form FROM ".FORM_TABLE.";", FORM_TABLE, array("id_form", "NULL", false, "", "nom_form", "", true, "Nom"));
		}
		
	?>
</div>
<?php
	
	layout::displayPageFooter();
	
?>
